<script>
import * as echarts from 'echarts';
import data from "@/views/system/dict/data.vue";
export default {
  props: {
    cdata: { // 使用小写的 cdata
      type: Array,
      required: true,
    }
  },
  data() {
    return {
      myChart: null
    };
  },
  created() {
  },
  watch: {
    cdata: {
      handler(newData) {
        this.updateChart(newData); // 更新图表
      },
      deep: true,
    },
  },
  mounted() {
    this.myChart = echarts.init(document.getElementById('main'));
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    this.updateChart(this.cdata); // 初始化图表
    myChart.setOption({
      tooltip: {
        trigger: 'item'
      },
      legend: {
        top: '5%',
        left: 'center'
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,
          padAngle: 5,
          itemStyle: {
            borderRadius: 10
          },
          label: {
            show: false,
            position: 'center'
          },
          emphasis: {
            label: {
              show: true,
              fontSize: 40,
              fontWeight: 'bold'
            }
          },
          labelLine: {
            show: false
          },
          data: this.Cdata
        }
      ]
    })
  },
  methods:{
    updateChart(data) {
      this.myChart.setOption({
        tooltip: { trigger: 'item' },
        legend: { top: '5%', left: 'center' },
        series: [{
          name: 'Access From',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,
          data: data,
          emphasis: {
            label: { show: true, fontSize: 40, fontWeight: 'bold' }
          }
        }]
      });
    }
  }
}
</script>

<template>
  <div id="main" style="width: 100%;height:300px;display: flex;justify-content: center; align-items: center; "></div>
</template>

<style scoped lang="scss">

</style>
